import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import type { App } from 'vue'

let routes: RouteRecordRaw[] = []

const routerModules = import.meta.globEager('./**/*.ts')
const modules: Array<RouteRecordRaw> = []

Object.keys(routerModules).forEach(key => {
	modules.push(...routerModules[key].default)
})

routes.push(...modules)

export const router = createRouter({
	history: createWebHashHistory(),
	routes,
})

export function setupRouter(app: App<Element>) {
	app.use(router)
}
